package br.com.citta.dao.impl;

import br.com.citta.business.entities.RecVinculado;
import br.com.citta.dao.RecVinculadoDao;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class RecVinculadoDaoImpl extends HibernateDaoSupport implements RecVinculadoDao {
    
    private StringBuilder sb;

    private void addOrdem(String ordem){
        if (ordem != null && !ordem.equals("")){
            sb.append(" order by ").append(ordem);
        } else {
            sb.append(" order by id.anoBase, nome");
        }
    }
    
    private List<RecVinculado> find(){
        return getHibernateTemplate().find(sb.toString());
    }
    
    public List<RecVinculado> findAll(String ordem){
        sb = new StringBuilder();
        sb.append("from RecVinculado");
        addOrdem(ordem);
        return find();
    }
    
    public List<RecVinculado> findByAnoBase(String anoBase, String ordem){
        sb = new StringBuilder();
        sb.append("from RecVinculado where id.anoBase = ").append(anoBase);
        addOrdem(ordem);
        return find();
    }
    
}
